# coding: utf-8
import csv

# def add():
# # csv 写入
#     with open('a.csv', 'w') as csvfile:
#         writer = csv.writer(csvfile)
#         writer.writerow(['id', 'name', 'age'])
#         writer.writerow(['10001', 'Mike', 20])
#         writer.writerow(['10002', 'Bob', 22])
#         writer.writerow(['10003', 'Jordan', 21])


# csv读取
list = []  ## 空列表
stt = [] ##

def hello():
   with open('china_cities_20180101.csv', 'r', encoding='utf-8') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        if row[111] == "长治":
            stt.append(row)
            continue;
        else:
            if row[2] == 'AQI':
                get(row)
            else:
                continue;
    creat()

def get(number):
    list.append(number)  ## 使用 append() 添加元素

def creat():
    changzhi = 0
    i= 10
    str = []
    for number in range(len(stt)):
        del stt[number][0]
        del stt[number][1]
        del stt[number][2]
        print(stt[number])

    for obj in range(len(list)):
        if list[obj][obj] != '':
            i = i+1
            changzhi = int(changzhi) + int(list[obj][111])
        else:
            continue;
    print('北京api平均值：=',int(changzhi) / int(i))

# 程序主入口
if __name__ == '__main__':
    hello()
